package com.wenwan.manage.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wenwan.manage.mapper.ReleaseTimesWaterAccountMapper;
import com.wenwan.manage.pojo.ReleaseTimesWaterAccount;
import com.wenwan.manage.service.ReleaseTimesWaterAccountService;
import com.wenwan.manage.setting.RegExpSetting;
import com.wenwan.manage.setting.StatusSetting;
import com.wenwan.manage.util.Util;

@Service
public class ReleaseTimesWaterAccountServiceImpl implements ReleaseTimesWaterAccountService {

	@Autowired
	private ReleaseTimesWaterAccountMapper releaseTimesWaterAccountMapper;

	@Override
	public Map<String, Object> create(String userId, String remarks, Boolean isSuccess, String orderNumberLocal,
			String orderNumberWeiXin, Double price, Double discount, Integer times, Integer giveTimes, Integer number) {
		// TODO Auto-generated method stub
		// DataToObject<Boolean> dto = new DataToObject<Boolean>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (userId != null && !userId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg(StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (remarks != null && remarks.length() < 1) {
			dto.put("data", false);
			dto.put("msg", StatusSetting.MSG_10050_LENGTH_IS_CAN_NOT_LESS_ONE_WORD);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg(StatusSetting.MSG_10050_LENGTH_IS_CAN_NOT_LESS_ONE_WORD);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", Util.UUID());
		map.put("createTime", Util.getTime());
		map.put("updateTime", Util.getTime());
		map.put("userId", userId);
		map.put("remarks", remarks);
		map.put("isSuccess", isSuccess);
		map.put("orderNumberLocal", orderNumberLocal);
		map.put("orderNumberWeiXin", orderNumberWeiXin);
		map.put("price", price);
		map.put("discount", discount);
		map.put("times", times);
		map.put("giveTimes", giveTimes);
		map.put("number", number);

		Boolean data = releaseTimesWaterAccountMapper.create(map);
		// dto.setData(data);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

	@Override
	public Map<String, Object> deleteById(String id) {
		// TODO Auto-generated method stub
		// DataToObject<Boolean> dto = new DataToObject<Boolean>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (id != null && !id.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);

		Boolean data = releaseTimesWaterAccountMapper.deleteById(map);
		// dto.setData(data);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

	@Override
	public Map<String, Object> update(String id, String userId, String remarks, Boolean isSuccess,
			String orderNumberLocal, String orderNumberWeiXin, Double price, Double discount, Integer times,
			Integer giveTimes, Integer number) {
		// TODO Auto-generated method stub
		// DataToObject<Boolean> dto = new DataToObject<Boolean>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (id != null && !id.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (userId != null && !userId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "userId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("userId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("updateTime", Util.getTime());
		map.put("userId", userId);
		map.put("remarks", remarks);
		map.put("isSuccess", isSuccess);
		map.put("orderNumberLocal", orderNumberLocal);
		map.put("orderNumberWeiXin", orderNumberWeiXin);
		map.put("price", price);
		map.put("discount", discount);
		map.put("times", times);
		map.put("giveTimes", giveTimes);
		map.put("number", number);

		Boolean data = releaseTimesWaterAccountMapper.update(map);
		// dto.setData(false);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

	@Override
	public Map<String, Object> selectAll(String yearMonth) {
		// TODO Auto-generated method stub
		// DataToObject<List<ReleaseTimesWaterAccount>> dto = new
		// DataToObject<List<ReleaseTimesWaterAccount>>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (yearMonth != null && !yearMonth.matches(RegExpSetting.YEAR_MONTH)) {
			dto.put("data", false);
			dto.put("msg", "yearMonth" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setMsg("yearMonth" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("yearMonth", yearMonth);

		List<ReleaseTimesWaterAccount> data = releaseTimesWaterAccountMapper.selectAll(map);
		// dto.setData(data);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

	@Override
	public Map<String, Object> selectOneById(String id) {
		// TODO Auto-generated method stub
		// DataToObject<ReleaseTimesWaterAccount> dto = new
		// DataToObject<ReleaseTimesWaterAccount>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (id != null && !id.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setMsg("id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);

		ReleaseTimesWaterAccount data = releaseTimesWaterAccountMapper.selectOneById(map);
		// dto.setData(data);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

}
